package com.yuexun.dhdoctor.module.survey.presenter.impl;


import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.survey.bean.SurveyDateBean;
import com.yuexun.dhdoctor.module.survey.model.ISurveyModel;
import com.yuexun.dhdoctor.module.survey.model.impl.SurveyModel;
import com.yuexun.dhdoctor.module.survey.presenter.ISurveyListPresenter;
import com.yuexun.dhdoctor.module.survey.ui.view.ISurveyListView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2017/8/22.
 */

public class SurveyListPresenter implements ISurveyListPresenter {
    private ISurveyModel model;
    private ISurveyListView view;

    public SurveyListPresenter(SurveyModel model, ISurveyListView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getSurveyList(Map<String, String> praise) {
        model.getSurveyList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<SurveyDateBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<SurveyDateBean> bean) {
                        view.showSurveyList(bean);
                    }
                });
    }
}
